<?php

include "init.php";
if ($_POST["nameid"] !== '') {
  $sqlshow = "SELECT `rp_id`, `rp_name`, `rp_create_datetime`, `rp_used_datetime` FROM `reward_pool` WHERE `rp_id`='" . (int) $_POST["nameid"] . "'";
  $show = mysqli_query($db_conn, $sqlshow);
  $showEcode = json_encode(mysqli_fetch_all($show));
  $resultDcode = json_decode($showEcode, true);
  $resultId = (int) $resultDcode[0][0];
  $userTime = $resultDcode[0][3];
  if (is_null($userTime)) {  
    $sql = "DELETE FROM `reward_pool` WHERE `rp_id`='" . (int) $_POST['nameid'] . "'";
    $result = mysqli_query($db_conn, $sql);
    $row = mysqli_affected_rows($db_conn);
    if ((int) $row === 1) {
      echo '刪除成功';
    } else {
      echo '刪除失敗';
    }
  } else {
    echo '已經領取不能刪除了';
  }
}
mysqli_close($db_conn);
